

package com.markerhub.controller;

        import cn.hutool.core.lang.UUID;
        import cn.hutool.core.map.MapUtil;
        import com.alibaba.excel.EasyExcel;
        import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
        import com.google.code.kaptcha.Producer;
        import com.markerhub.common.lang.Const;
        import com.markerhub.common.lang.Result;
        import com.markerhub.common.lang.retunData;
        import com.markerhub.entity.*;
        import com.markerhub.mapper.TFacilityFunctionMapper;
        import com.markerhub.mapper.TPayOrderMapper;
        import com.markerhub.povo.TFacilityFunctionVo;
        import com.markerhub.povo.TFacilityReqairVo;
        import com.markerhub.povo.TPayOrderVo;
        import com.markerhub.service.*;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.security.access.prepost.PreAuthorize;
        import org.springframework.util.Base64Utils;
        import org.springframework.util.StringUtils;
        import org.springframework.web.bind.annotation.*;
        import sun.misc.BASE64Encoder;

        import javax.imageio.ImageIO;
        import javax.servlet.http.HttpServletResponse;
        import java.awt.image.BufferedImage;
        import java.io.ByteArrayOutputStream;
        import java.io.IOException;
        import java.net.URLEncoder;
        import java.security.Principal;
        import java.text.ParseException;
        import java.text.SimpleDateFormat;
        import java.util.ArrayList;
        import java.util.Date;
        import java.util.List;

@RestController
@RequestMapping("/BaseInfoController")
public class BaseInfoController extends BaseController{

    @Autowired
    Producer producer;

    @Autowired
    TFacilityBaseService tFacilityBaseService;
    @Autowired
    TFacilityFunctionService tFacilityFunctionService;


    @Autowired
    TFacilityFunctionMapper tFacilityFunctionMapper;
    @Autowired
    TFacilityReqairService tFacilityReqairService;

    @Autowired
    TPayOrderService tPayOrderService;
    @Autowired
    TPayOrderMapper tPayOrderMapper;
/*
*依据ID 查询对应的设备信息 ===
* */
    @GetMapping("/infoBase/{id}")
    @ResponseBody
    public Result infoBase(@PathVariable("id") String id ){
        TFacilityBase byId = tFacilityBaseService.getById(id);
        //System.out.println("依据ID 查询对应的设备信息 === "+byId);
        return Result.succ(byId);
    }
    @GetMapping("/infoFunction/{id}")
    @ResponseBody
    public Result infoFunction(@PathVariable("id") String id ){
        // byId = tFacilityFunctionService.getById(id);
        List<TFacilityFunction> id1 = tFacilityFunctionService.list(new QueryWrapper<TFacilityFunction>().eq("baseid", id));
        //System.out.println("依据ID 查询对应的设备信息 === "+byId);
        List<TFacilityFunctionVo> tFacilityFunctionVos = new ArrayList<>();
        for (TFacilityFunction TFacilityFunction:id1) {
            TFacilityFunctionVo tFacilityFunctionVo = new TFacilityFunctionVo();
            tFacilityFunctionVo.setFunctionid(TFacilityFunction.getFunctionid());
            tFacilityFunctionVo.setFunctionType(TFacilityFunction.getFunctionType());
            tFacilityFunctionVo.setFunctionStatus(TFacilityFunction.getFunctionStatus());
            tFacilityFunctionVo.setBaseid(TFacilityFunction.getBaseid());
            tFacilityFunctionVo.setMoney(TFacilityFunction.getMoney());
            tFacilityFunctionVo.setFunctionTime(TFacilityFunction.getFunctionTime());
            tFacilityFunctionVo.setDescribes(TFacilityFunction.getDescribes());
            if (TFacilityFunction.getFunctionStatus()==1){
                tFacilityFunctionVo.setTab0(true);
            }else {
                tFacilityFunctionVo.setTab0(false);
            }
            tFacilityFunctionVos.add(tFacilityFunctionVo);
        }
        return Result.succ(tFacilityFunctionVos);
    }

    @GetMapping("/list")
    //@PreAuthorize("hasAuthority('sys:reqair:list')")
    @ResponseBody
    public retunData list(Integer size, Integer current, String number, String projectid) {
        Integer pages=(current-1)*size;
        retunData retunData = new retunData();
        if (size==0&&current==0){
            List<TFacilityReqair> list = tFacilityReqairService.list();
            retunData.setData(list);
            return retunData;
        }
        List<TFacilityReqairVo> pageData = tFacilityReqairService.getReqairList(pages, current,number,projectid);
        retunData.setData(pageData);
        retunData.setCount(pageData.size());
        return retunData;
    }


//    @GetMapping("/Orderlist")
//  //  @PreAuthorize("hasAuthority('sys:order:list')")
//    @ResponseBody
//    public retunData Orderlist(Integer page, Integer limit, String number , String orderNumber, String projectid, String date1, String date2,  String defarystatus ) throws ParseException {
//
//        System.out.println(page);
//        System.out.println(limit);
//        System.out.println(projectid);
//        System.out.println(orderNumber);
//        System.out.println(defarystatus);
//        Date dateup = null;
//        Date datedown = null;
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        if (!date1.equals("")){
//            dateup = simpleDateFormat.parse(date1);
//        }
//        if (!date2.equals("")){
//            datedown = simpleDateFormat.parse(date2);
//        }
//        if (page==0&&limit==0){
//            List<TPayOrderVo> list = tPayOrderService.getOrderList(0,0,number,orderNumber,projectid,dateup,datedown,defarystatus);
//            retunData retunData1 = new retunData();
//            retunData1.setData(list);
//            return retunData1;
//        }
//        Integer pages=(page-1)*limit;
//
//        List<TPayOrderVo> TFacilityBaseVoList= tPayOrderService.getOrderList(pages,limit,number,orderNumber,projectid,dateup,datedown,defarystatus);
//        List<TPayOrderVo> count= tPayOrderService.getOrderList(0,0,number,orderNumber,projectid,dateup,datedown,defarystatus);
//        // System.out.println("List<TFacilityBaseVo> count "+count);
//        retunData retunData = new retunData();
//        retunData.setData(TFacilityBaseVoList);
//        retunData.setCount(count.size());
//
//
//        return retunData;
//    }
//

    @GetMapping("/getlist")
    //@PreAuthorize("hasAuthority('sys:reqair:list')")
    @ResponseBody
    public retunData getlist(Integer size, Integer current, String number, String projectid) {
        List<TPayOrder> getlist = tPayOrderMapper.getlist();
        retunData retunData = new retunData();
        retunData.setData(getlist);
        retunData.setCount(getlist.size());


        return retunData;
    }

}
